package com.home766.controller.shop;

import com.home766.entity.CustomerService;
import com.home766.entity.CustomerServicePage;
import com.home766.service.CustomerServicePageService;
import com.home766.service.CustomerSvService;
import net.biz.Message;
import net.biz.controller.admin.BaseController;
import net.biz.entity.Member;
import net.biz.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Controller("CustomerServiceShopController")
@RequestMapping("/shops/customerService")
public class CustomerServiceController extends BaseController {
	@Resource(name="customerSvServiceImpl")
	private CustomerSvService customerSvService;
	@Resource(name="memberServiceImpl")
	private MemberService memberService;
	@Autowired
	private CustomerServicePageService customerServicePageService;
	/***
	 *頁面跳轉
	 * @return
	 */
	@RequestMapping("/content")
	public String customerServicePage(ModelMap modelMap){
		List<CustomerServicePage> list = customerServicePageService.findAll();
		Member member = memberService.getCurrent();
		modelMap.addAttribute("member",member);
		modelMap.addAttribute("list",list);
		return "/shop/customerService/content";
	}
	/***
	 * 预约
	 * @param customerService
	 * @return
	 */
	@RequestMapping("/add")
	@ResponseBody
	public Message add(CustomerService customerService){
		Message msg = new Message();
		try {
			Member member = memberService.getCurrent();
			if(member==null){
				msg.setContent("errorLogin");
				return msg;
			}
			customerService.setCreateDate(new Date());
			customerService.setAddress(member.getAddress());
			customerService.setcName(member.getName());
			customerService.setPhone(member.getPhone());
			customerService.setHandle(0);
			customerSvService.save(customerService);
			msg.setContent("success");
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			msg.setContent("error");
		}
		return msg;
	}
}
